﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nop.Web.Framework.UI
{
    public static class StringExtension
    {
        /// <summary>
        /// 重载string.Tostring 方法
        /// </summary>
        /// <param name="source"></param>
        /// <param name="length"></param>
        /// <param name="seperator"></param>
        /// <returns></returns>
        public static string ToStringLength(this string source, int length, string seperator = "...")
        {
            var sourceStr = source.ToString().Trim();
            if (!string.IsNullOrEmpty(sourceStr))
            {
                if (sourceStr.Length > length)
                {
                    return string.Format("{0}{1}", sourceStr.Substring(0, length), seperator);
                }
            }
            return sourceStr;
        }
    }
}
